# coding =UTF-8
'''
反射库
'''
import requests
from my_test.tools.tools import *
from configparser import ConfigParser


class Keylib:

    def __init__(self):
        self.s = requests.session()
        self.conf = ConfigParser()
        self.conf.read(pro_path() + r'\conf.ini', encoding='utf-8')
        self.host = self.conf.get('host', 'host')

    @print_exception
    def get(self, url=None, headers=None, params=None):
        try:
            url = self.host + url
            return self.s.get(url=url, headers=headers, params=params)
        except:
            raise Exception(rf'get请求时引发异常:url={url}, headers={headers}, params={params}')

    @print_exception
    def post(self, url=None, headers=None, data=None):
        try:
            url = self.host + url
            return self.s.post(url=url, headers=headers, data=data)
        except:
            raise Exception(rf'post请求时引发异常:url={url}, headers={headers}, params={data}')

    @print_exception
    def shouldin(self, exp, asc):
        if exp in asc.text:
            return True
        else:
            return False

    @print_exception
    def shouldeq(self, exp, asc):
        if exp == asc.text:
            return True
        else:
            return False

    @print_exception
    def status_code(self, exp, asc):
        if exp == str(asc.status_code):
            return True
        else:
            return False

    @print_exception
    def should_url(self, exp, asc):
        if exp == asc.url:
            return True
        else:
            return False
